﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
using System.Data.OleDb;
using System.Xml;
using System.Globalization;


namespace pistolety3
{
    class zebra3
    {
        public void wydrukZebra(string id, String etykieta, String drukarka)
        {
            string text = "";

            if (id.Length == 6)
            {
                text = id.Substring(0,3)+"-"+id.Substring(3,2)+"-"+id.Substring(5,1);                
            }
            else
            {
                return;
            }

            try
            {                
                using (StreamReader sr = new StreamReader(etykieta))
                {
                    String line = null;
                    while ((line = sr.ReadLine()) != null)
                    {
                        line = line.Replace("<barcode>", id);
                        line = line.Replace("<podpis>", text);
                        etykieta += line;
                    }
                }
                //MessageBox.Show(id+"\n\n"+text);
                PrintDialog pd = new PrintDialog();
                pd.PrinterSettings = new PrinterSettings();
                zebraWydruk.RawPrinterHelper.SendStringToPrinter(drukarka, etykieta);                
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.ToString());
            }
        }

        public String konfigurator(String parametr)
        {
            String value = "";
            XmlTextReader xtr = new XmlTextReader(@"c:\kan\konfigurator_gunmachine.xml");
            while (xtr.Read())
            {
                if (xtr.MoveToContent() == XmlNodeType.Element && xtr.Name == parametr)
                {
                    value = xtr.ReadString();
                }
            }
            return value;
        }
    }
}
